'''
Created on 19/06/2012

@author: rcasal
'''

from gluon.dal import ADAPTERS, MSSQLAdapter, DAL

class MSSQLAdapter3(MSSQLAdapter):
    '''
    classdocs
    '''
    
    def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8',
                 credential_decoder=lambda x:x, driver_args={},
                    adapter_args={}, fake_connect=False):
        super(MSSQLAdapter3, self).__init__(db, uri, pool_size, folder, db_codec, credential_decoder, driver_args, adapter_args)
        
        self.dbengine = "mssql3"
        
    def represent(self, obj, fieldtype):
        value = MSSQLAdapter.represent(self, obj, fieldtype)
        
        if fieldtype == 'datetime':
            value = value.replace('-','')
        return value

ADAPTERS.update({'mssql3':MSSQLAdapter3})    

class DAL2(DAL):
    '''
    Class DAL2 extends DAL
    Obtiene los ADAPTERS con MMSQLApapter3 incluido
    '''
    
    def __init__(self, uri='sqlite://dummy.db', 
        pool_size=0, folder=None, 
        db_codec='UTF-8', check_reserved=None, 
        migrate=True, fake_migrate=False, 
        migrate_enabled=True, fake_migrate_all=False, 
        decode_credentials=False, driver_args=None, 
        adapter_args=None, attempts=5, auto_import=False):
        DAL.__init__(self, uri=uri, pool_size=pool_size, folder=folder, db_codec=db_codec, check_reserved=check_reserved, migrate=migrate, fake_migrate=fake_migrate, migrate_enabled=migrate_enabled, fake_migrate_all=fake_migrate_all, decode_credentials=decode_credentials, driver_args=driver_args, adapter_args=adapter_args, attempts=attempts, auto_import=auto_import)
    
    def contiene_tabla(self, nombre):
        for tabla in self.tables:
            if tabla == nombre:
                return True
        return False
    

    